$(function () {
    $("#app").on("mousedown", function (evt) {
        let e = evt || event
        //当前鼠标位置相对当前元素的偏移量
        let left = e.offsetX
        let top = e.offsetY
        //浏览器窗口的事件
        $(document).on("mousemove", function (evt) {
            let e = evt || event
            //元素app离浏览器的left top值
            let x = e.pageX - left
            let y = e.pageY - top
            if (x < 0) {
                x = 0
            }
            if (y < 0) {
                y = 0
            }

            let maxx = window.innerWidth - $("#app")[0].offsetWidth
            if (x > maxx) {
                x = maxx
            }
            let maxy = window.innerHeight - $("#app")[0].offsetHeight
            if (y > maxy) {
                y = maxy
            }
            $("#app").css({
                left: x + "px",
                top: y + "px"

            })
        })
        $(document).on("mouseup", function () {
            $(document).off("mousemove")
        })
    })
})